//
//  GameManager.h
//  DiceWar
//
//  Created by Xiao  Feng on 16/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#ifndef CLASSES_GAME_SCENEMANAGER_H_
#define CLASSES_GAME_SCENEMANAGER_H_


#include "cocos2d.h"

/** SceneManager is a singleton, it is responsible for organizing and initializing all the scenes and layers
 inside a scene, all the scenes and layers will be created inside this class 
 */
class SceneManager
{
public:
    SceneManager();
    ~SceneManager();
    
    enum SceneType
    {
        kMainMenuScene,
        kMapSelectionScene,
        kGameScene,
        kWarSettingScene
    };
    
    bool init();
    
    static SceneManager& sharedSceneManager();
    cocos2d::CCScene* getScene(SceneType scene);

    void startWithScene(SceneType pScene);
    void switchToScene(SceneType scene);
    
private:
    template<typename LayerType>
    cocos2d::CCScene* createSceneWithLayer();
    
    void registerScene(SceneType type, cocos2d::CCScene* pScene);
    
private:
    typedef std::map<SceneType, cocos2d::CCScene*> SceneMap;
    SceneMap m_sceneMap;
};

template<typename LayerType>
cocos2d::CCScene* SceneManager::createSceneWithLayer()
{    
    cocos2d::CCScene* pScene = cocos2d::CCScene::node();
    CCAssert(pScene, "Scene can't be created!");
    
    if (!pScene) return NULL;
    pScene->retain();
    
    LayerType* pLayer = LayerType::node();
    CCAssert(pLayer, "Layer can't be created!");
    
    if (!pLayer) return pScene;
    pScene->addChild(pLayer);
    
    return pScene;
}


#endif //CLASSES_GAME_GAMEMANAGER_H_
